home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 37
/
Aminet 37 (2000)(Schatztruhe)[!][Jun 2000].iso
/
Aminet
/
dev
/
misc
/
AWNP_2-39.lha
/
AWNP
/
AWNP-Docs
/
Tutorials
/
tutorial4.rx
< prev
next >
Wrap
Text File
|
2000-01-03
|
7KB
|
289 lines
/*Tutorial 3 for AWNPipe*/
envname='GUITutorial4'
call setdefaults()
call buildgui()
topipe('id 'savegad' dis 1 ref')
/*main loop*/
do while ~eof(ca)
call topipe('continue')
in= readln(ca)
parse var in in1 in2 in3 in4 .
if in1='gadget' then call gadget()
if in1='menu' then call menu()
if in1='close' then call windowclosed()
if in1='iconify' then call iconify()
if in1='app' then call app()
end
/*end of main loop*/
exit
gadget:
if in2=agegad then age=in3 Close
if in2=sexgad then sex=in3
if in2=knogad then knowledge=in3
if in2=basgad then basic=in3
if in2=aregad then arexx=in3
if in2=cgad then c=in3
if in2=asmgad then asm=in3
/* the return from a string gadget is parsed differently since it can be more
then 1 word. */
if in2=namegad then do
parse var in . . in3
/*strip it since arexx parsing adds the leading space to the last string
assignment*/
name=strip(in3)
if name='' then call topipe('id 'savegad' dis 1 ref')
else call topipe('id 'savegad' dis 0 ref')
end
if in2=dongad then do
showtx(0, 'Normal exit *nname' name '*nage' age '*nsex' sex '*nknowledge' knowledge '*nbasic' basic 'arexx' arexx 'c' c 'asm' asm)
exit
end
if in2=resgad then call resetform()
if in2=savegad then call saveform()
if in2=loadgad then call loadform()
if in2=cangad then do
showtx(300,'user canceled')
exit
end
return
windowclosed:
showtx(300,'User aborted with CTRL BackSlash or closed window.')
exit
return
menu:
if in2=0 then do
if in3=0 then do
if in4=0 then call setenvarc()
if in4=1 then call unsetenvarc()
end
if in3=2 then showtx(500,' Tutorial 4 for AWNP *n by William Parker')
end
if in2=1 then do
if in3=0 then do
showtx(0, 'name' name '*nage' age '*nsex' sex '*nknowledge' knowledge '*nbasic' basic 'arexx' arexx 'c' c 'asm' asm)
end
if in3=1 then do
if in4=0 then showtx(0, 'name' name '*nage' age '*nsex' sex)
if in4=1 then showtx(0, 'knowledge' knowledge '*nbasic' basic 'arexx' arexx 'c' c 'asm' asm)
end
end
return
setdefaults:
name='unset'
age=30
sex=0
knowledge=0
basic=0
c=0
asm=0
arexx=0
return
buildgui:
/* get our window size and position */
call getenv()
/* Open pipe 'tut2' with GUI creation option '/xc' */
call open(ca,"awnpipe:tut4/xc")
/* define the window */
/* The first line oF every GUI is the window definition. The window is titled
"Tutorial 2" and its elements will be laid out verticaly (v). It has a
closegadget (cg) , depthgadget (dg) , and dragbar (db). It will have spaces
inbetween its gadgets (si). It will open on the topleft (tl) of the screen
becoming active (a) when opened. The window can be icoified (ig) and modified
(m). It is an app window (app) . It can be sized (SG) but not verticaly (fh)*/
call topipe(' "Tutorial 4" v cg dg db si a ig sg fh m app ii "tutorial4.rx" 'windowdef)
/* define the gadgets*/
call topipe(' layout b 0 v')
/* Labels are used to tell the user what information to enter in each gadget.
These labels are unatached (ua) when they are defined so don't go directly
into the GUI. Instead they are attached to the following gadget by the
childlabel (chl) keyword. */
call topipe(' label gt "Name: " ua')
namegad=topipe('string lj chl')
call topipe(' label gt "Age: " ua')
agegad=topipe('integer chl minn 5 maxn 115 arrows defn 30 weiw 0')
call topipe(' label gt "Sex: " ua')
sexgad=topipe('radiobutton rl "Male|Female" chl')
call topipe(' label gt "Knowledge: " ua')
knogad=topipe('chooser pu cl "Novice|Average|Good|Expert" chl')
call topipe(' label gt "Language(s): " ua')
call topipe(' layout b 0 chl')
basgad=topipe('checkbox gt "Basic " chl')
aregad=topipe('checkbox gt "Arexx " chl')
cgad=topipe('checkbox gt "C " chl')
asmgad=topipe('checkbox gt "ASM " chl')
call topipe(' le')
call topipe(' le')
call topipe(' layout si so')
savegad= topipe('button gt "Save" ')
loadgad= topipe('button gt "Load" ')
resgad= topipe('button gt "Reset Form" ')
dongad= topipe('button gt "Done" c')
cangad= topipe('button gt "Cancel" c')
call topipe(' le')
call topipe(' menu gt "Project|Window|$@SSnapshot|$@UUnSnapshot|-|About"')
call topipe(' menu gt "Data|@AShow all data|Show part|$@PPersonal|$@SSkill"')
getfilegad=topipe('getfile gt "Select Information File" fn "t:" ua pat "#?.tut3"')
/*open the GUI window*/
call topipe("open")
return
topipe:
/* this routine does error checking on lines written to pipe.*/
/*get line to output*/
parse arg out
/* write to the pipe*/
call writeln(ca,out)
/*get responce and parse it.*/
res=readln(ca)
parse var res res1 res2 .
/* if all is ok return the second part of the responce (usualy the GID)*/
if res1='ok' then return(res2)
/* something went wrong, we notify the user then exit */
/*show problem line and responce (reponce may be just a blank line)*/
say 'error from: 'out
say ' responce: ' res
exit
resetform:
call topipe('id 'agegad' defn 30 ref')
call topipe('id 'sexgad' s 0 ref')
call topipe('id 'knogad' s 0 ref ')
call topipe('id 'basgad' s 0 ref')
call topipe('id 'aregad' s 0 ref')
call topipe('id 'cgad' s 0 ref ')
call topipe('id 'asmgad' s 0 ref')
call topipe('id 'namegad' gt "" ref')
topipe('id 'savegad' dis 1 ref')
call setdefaults()
return
saveform:
call open(form,'t:'name'.tut3','W')
call writech(form,age sex knowledge basic arexx c asm name)
call close(form)
return
loadform:
call writeln(ca,'id 'getfilegad' fn "t:" s 1')
res=readln(ca);
parse var res res1 '"' filename '"'
loadapp:
if res1~=0 then do
call open(form,filename,'R')
formin=readch(form,1000)
parse var formin age sex knowledge basic arexx c asm name
name=substr(name,2)
call close(form)
/*uniconify in case its needed*/
call topipe('id 0 s 64')
call topipe('id 'agegad' defn 'age' ref')
call topipe('id 'sexgad' s 'sex' ref')
call topipe('id 'knogad' s 'knowledge' ref ')
call topipe('id 'basgad' s 'basic' ref')
call topipe('id 'aregad' s 'arexx' ref')
call topipe('id 'cgad' s 'c' ref ')
call topipe('id 'asmgad' s 'asm' ref')
call topipe('id 'namegad' gt "'name'" ref')
if name='' then call topipe('id 'savegad' dis 1 ref')
else call topipe('id 'savegad' dis 0 ref')
end
return
app:
parse var in . in2
filename=strip(in2)
if (right(filename,5)='.tut3') then do
res1=1
call loadapp()
end
return
/* send a modify command to iconify/uniconify window and remember the current
state of the window*/
iconify:
iconified=in2
if in2=1 then call topipe('id 0 s 32')
else call topipe('id 0 s 64')
return
showtx:
call open(ptx,'awnpipe:tut3txt/xc')
call writeln(ptx,'db dg "Tutorial 4" q cg cm m a so si ')
call writeln(ptx,'label lj gt "'arg(2)'"')
call writeln(ptx,'open')
if arg(1)~=0 then call writeln(ptx,'tick 'arg(1))
else call writeln(ptx,'m')
call close(ptx)
return(0)
setenv:
call writeln(ca,'id 0 read')
windowr=readln(ca)
if open(env,'env:'envname,'W') then do
call writech(env,windowr)
close(env)
end
return(0)
setenvarc:
call setenv()
address command 'copy env:'envname 'envarc:'envname' >nil:'
return
unsetenvarc:
if exists('envarc:'envname) then delete('envarc:'envname)
if exists('env:'envname) then delete('env:'envname)
return
getenv:
windowdef='tl'
if(open(env,'env:'envname,'R')) then do
windowt=readln(env)
parse var windowt wl wt ww wh .
if (datatype(wt,N) &datatype(wl,N) &datatype(ww,N) & datatype(wh,N) ) then
windowdef= 'top' wt 'left' wl 'width' ww 'height' 1
close(env)
end
return